package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.EscapeRefugeFacilities;
import com.ruoyi.system.mapper.EscapeRefugeFacilitiesMapper;
import com.ruoyi.system.service.EscapeRefugeFacilitiesService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 逃生避难设施(EscapeRefugeFacilities)表服务实现类
 *
 * @author makejava
 * @since 2022-11-16 15:24:15
 */
@Service("escapeRefugeFacilitiesService")
public class EscapeRefugeFacilitiesServiceImpl implements EscapeRefugeFacilitiesService {
    @Resource
    private EscapeRefugeFacilitiesMapper escapeRefugeFacilitiesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public EscapeRefugeFacilities queryById(Integer id) {
        return this.escapeRefugeFacilitiesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param escapeRefugeFacilities 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<EscapeRefugeFacilities> queryByPage(EscapeRefugeFacilities escapeRefugeFacilities, PageRequest pageRequest) {
        long total = this.escapeRefugeFacilitiesDao.count(escapeRefugeFacilities);
        return new PageImpl<>(this.escapeRefugeFacilitiesDao.queryAllByLimit(escapeRefugeFacilities, pageRequest), pageRequest, total);
    }

    @Override
    public List<EscapeRefugeFacilities> selectList(EscapeRefugeFacilities escapeRefugeFacilities) {
        return escapeRefugeFacilitiesDao.queryAll(escapeRefugeFacilities);
    }

    /**
     * 新增数据
     *
     * @param escapeRefugeFacilities 实例对象
     * @return 实例对象
     */
    @Override
    public EscapeRefugeFacilities insert(EscapeRefugeFacilities escapeRefugeFacilities) {
        this.escapeRefugeFacilitiesDao.insert(escapeRefugeFacilities);
        return escapeRefugeFacilities;
    }

    /**
     * 修改数据
     *
     * @param escapeRefugeFacilities 实例对象
     * @return 实例对象
     */
    @Override
    public EscapeRefugeFacilities update(EscapeRefugeFacilities escapeRefugeFacilities) {
        this.escapeRefugeFacilitiesDao.update(escapeRefugeFacilities);
        return this.queryById(escapeRefugeFacilities.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.escapeRefugeFacilitiesDao.deleteById(id) > 0;
    }

    @Override
    public String importExcel(List<EscapeRefugeFacilities> escapeRefugeFacilitiess, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(escapeRefugeFacilitiess) || escapeRefugeFacilitiess.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        escapeRefugeFacilitiesDao.insertBatch(escapeRefugeFacilitiess);
        return "成功";
    }
}
